package com.shengdou.as.slopsapptest.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by AS on 2016/11/24.
 */

public class DateUtils {
    /**
     * 获取当前日期
     *
     * @param
     * @return date
     */
    public static String StrToDate() {

        String str = new SimpleDateFormat("yyyy-MM-dd HH:").format(new Date(System.currentTimeMillis()));
        ;

        return str;
    }
    /*将字符串转为时间戳*/

    public static long getStringToDate() {

        String sdf = new SimpleDateFormat("mm").format(new Date(System.currentTimeMillis()));
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String time = StrToDate() + Integer.parseInt(sdf) / 5 * 5 + "";
        LogUtil.e("time", time);
        Date date = null;
        try {
            date = formatter.parse(time);

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date.getTime() / 1000;

    }

    /**
     * 格式化数据库时间戳
     */
    public static String stringFormateData(Long time) {
        String dayAfter = null;
        try {
            /**获取日期解析选择的日期*/
            Calendar c = Calendar.getInstance();
            Date date = null;
            String d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(time * 1000));
            date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(d);
            c.setTime(date);
            dayAfter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(c.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dayAfter;
    }

    /**
     * 格式化数据库时间戳
     */
    public static String stringFormateMin(Long time) {
        String dayAfter = null;
        try {
            /**获取日期解析选择的日期*/
            Calendar c = Calendar.getInstance();
            Date date = null;
            String d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(time * 1000));
            date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(d);
            c.setTime(date);
            dayAfter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dayAfter;
    }

    /**
     * 格式化数据库时间戳
     */
    public static String stringFormateDate(Long time) {
        String dayAfter = null;
        try {
            /**获取日期解析选择的日期*/
            Calendar c = Calendar.getInstance();
            Date date = null;
            String d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(time * 1000));
            date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(d);
            c.setTime(date);
            dayAfter = new SimpleDateFormat("yy-MM-dd").format(c.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dayAfter;
    }

    /**
     * 格式化数据库时间戳
     */
    public static String stringFormateMMDD(Long time) {
        String dayAfter = null;
        try {
            /**获取日期解析选择的日期*/
            Calendar c = Calendar.getInstance();
            Date date = null;
            String d = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date(time * 1000));
            date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").parse(d);
            c.setTime(date);
            dayAfter = new SimpleDateFormat("yyyy/MM/dd").format(c.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dayAfter;
    }

    /**
     * 格式化数据库时间戳
     */
    public static String stringFormateTime(Long time) {
        String dayAfter = null;
        try {
            /**获取日期解析选择的日期*/
            Calendar c = Calendar.getInstance();
            Date date = null;
            String d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(time * 1000));
            date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(d);
            c.setTime(date);
            dayAfter = new SimpleDateFormat("HH:mm:ss").format(c.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dayAfter;
    }

    /**
     * 格式化数据库时间戳
     */
    public static String stringIntTime(Long time) {
        String dayAfter = null;
        try {
            /**获取日期解析选择的日期*/
            Calendar c = Calendar.getInstance();
            Date date = null;
            String d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(time * 1000));
            date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(d);
            c.setTime(date);
            dayAfter = new SimpleDateFormat("HH").format(c.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dayAfter;
    }

    /**
     * 格式化数据库时间戳
     */
    public static int stringIntWeek(Long time) {
        int dayAfter = 0;
        try {
            /**获取日期解析选择的日期*/
            Calendar c = Calendar.getInstance();
            Date date = null;
            String d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(time * 1000));
            date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(d);
            c.setTime(date);
            String day = new SimpleDateFormat("dd").format(c.getTime());
            dayAfter = Integer.parseInt(day);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dayAfter;
    }
}
